package com.internal.Internalhibernate.server.dao;

// Generated Feb 24, 2012 1:32:12 PM by Hibernate Tools 3.3.0.GA

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.internal.Internalhibernate.client.AdmDocuments;
import com.internal.Internalhibernate.server.SessionFactoryUtil;

/**
 * Home object for domain model class AdmDocuments.
 * 
 * @see dao.AdmDocuments
 * @author Hibernate Tools
 */
public class AdmDocumentsDAO {
	private static final Log log = LogFactory.getLog(AdmDocumentsDAO.class);

	private final SessionFactory sessionFactory = SessionFactoryUtil
			.getSessionFactory();

	public void persist(AdmDocuments transientInstance) {
		log.debug("persisting AdmDocuments instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.persist(transientInstance);
			trans.commit();
			log.debug("persist successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(AdmDocuments instance) {
		log.debug("attaching dirty AdmDocuments instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.saveOrUpdate(instance);
			trans.commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(AdmDocuments instance) {
		log.debug("attaching clean AdmDocuments instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.lock(instance, LockMode.NONE);
			trans.commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(AdmDocuments persistentInstance) {
		log.debug("deleting AdmDocuments instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.delete(persistentInstance);
			trans.commit();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("delete failed", re);
			throw re;
		}
	}

	public AdmDocuments merge(AdmDocuments detachedInstance) {
		log.debug("merging AdmDocuments instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			AdmDocuments result = (AdmDocuments) session
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("merge failed", re);
			throw re;
		}
	}

	public AdmDocuments findById(short id) {
		log.debug("getting AdmDocuments instance with id: " + id);
		try {
			Session session = sessionFactory.getCurrentSession();
			session.beginTransaction();
			AdmDocuments instance = (AdmDocuments) session.get(
					"com.internal.Internalhibernate.client.AdmDocuments", id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<AdmDocuments> getAllDocuments() {
		log.info("Get all AdmDocuments");
		List<AdmDocuments> docList = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			session.beginTransaction();
			Query query = session.createQuery("from AdmDocuments ");
			docList = query.list();

		} catch (RuntimeException re) {
			log.error("getAllDocuments failed", re);
			throw re;
		}
		return docList;
	}

}
